package com.sf.business.appointment.controller;

import com.sf.business.appointment.domain.BusCheckout;
import com.sf.business.appointment.qo.BusCheckoutQO;
import com.sf.business.appointment.service.IBusCheckoutService;
import com.sf.business.appointment.vo.BusCheckoutVO;
import com.sf.common.annotation.Anonymous;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.core.page.TableDataInfo;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结算单Controller
 * 
 * @author liuhe
 * @date 2025-03-23
 */
@RestController
@Anonymous  // 可以匿名访问 (跳过 SecurityFilterChain)
@RequestMapping("/appointment/checkout")
public class BusCheckoutController extends BaseController
{
    @Autowired
    private IBusCheckoutService busCheckoutService;

    /**
     * 查询结算单列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:list')")
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest req, BusCheckoutQO vo)
    {
        startPage();

        System.out.println(vo.getEndActualArrivalTime());

        List<BusCheckout> list = busCheckoutService.selectBusCheckoutList(vo);
        return getDataTable(list);
    }

    /**
     * 导出结算单列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:export')")
    @Log(title = "结算单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusCheckoutQO vo)
    {
        List<BusCheckout> list = busCheckoutService.selectBusCheckoutList(vo);
        ExcelUtil<BusCheckout> util = new ExcelUtil<BusCheckout>(BusCheckout.class);
        util.exportExcel(response, list, "结算单数据");
    }

    /**
     * 获取结算单详细信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busCheckoutService.selectBusCheckoutById(id));
    }

    /**
     * 新增结算单
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:add')")
    @Log(title = "结算单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCheckoutVO vo)
    {
        return toAjax(busCheckoutService.insertBusCheckout(vo));
    }

    /**
     * 修改结算单
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:edit')")
    @Log(title = "结算单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCheckoutVO vo)
    {
        return toAjax(busCheckoutService.updateBusCheckout(vo));
    }

    /**
     * 删除结算单
     */
    @PreAuthorize("@ss.hasPermi('appointment:checkout:remove')")
    @Log(title = "结算单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(busCheckoutService.deleteBusCheckoutById(id));
    }

    /**
     * 支付结算单
     */
    @Log(title = "支付", businessType = BusinessType.UPDATE)
    @PutMapping("/pay/{id}")
    public AjaxResult pay(@PathVariable Long id)
    {
        busCheckoutService.pay(id);
        return AjaxResult.success();
    }
}
